#coding:utf-8
#! ‪C:\Developer\python36\python3.exe


from PIL import Image
from selenium.webdriver.remote.command import Command
import selenium.webdriver
from selenium.webdriver.common.action_chains import ActionChains
import lxml
import lxml.etree
import go
from getMore import *
from login import *
from saveHtml import *
from getData import *


url = 'https://www.zhihu.com/#signin'

driver = selenium.webdriver.Chrome()#打开一个浏览器
driver.maximize_window()#浏览器最大化
driver.get(url)
time.sleep(2)
driver.find_element_by_class_name('qrcode-signin-cut-button').click()#找到密码登录的标签
time.sleep(1)
driver.find_element_by_name('account').send_keys('17512067801')#输入账号
time.sleep(1)
driver.find_element_by_name('password').send_keys('**********')#输入密码
time.sleep(3)
html = driver.page_source
myTree = lxml.etree.HTML(html)
imgUrl = myTree.xpath('//img[@class="Captcha-image"]/@src')[0]#得到验证码链接，用来命名图片
url = 'http://www.zhihu.com'+imgUrl
while '首页' not in driver.page_source:#如果没登录成功，则继续调用验证码识别和登录的方法
    time.sleep(2)
    crackVerify(driver,url)#调用验证码识别和登录的方法
    time.sleep(2)



# 滚动
# scroll(driver)


#阅读全文
time.sleep(2)
more(driver)

time.sleep(5)

#将点击了’阅读全文‘后的html保存到本地
savePage(driver)

time.sleep(5)

#讲需要的数据保存到zhihu.txt
getDatas()

